package com.zhoug.tmap.location;


import android.text.TextUtils;

import androidx.annotation.Keep;

import java.io.Serializable;

/**
 * 地址
 *
 * @Author HK-LJJ
 * @Date 2019/12/27
 * @Description
 */
@Keep
public final class ZAddress implements Serializable {
    public final double latitude;//纬度
    public final double longitude;//经度
    public final String country;//国家:中国
    public final String countryCode;//国家代码:GCJ02
    public final String province;//省份:重庆市
    public final String provinceCode;//省份:重庆市 500
    public final String city;//城市:重庆市
    public final String cityCode;//城市代码:500
    public final String district;//区:渝中区
    public final String districtCode;//区:500103
    public final String town;//区县的下级:街道,镇:宝圣湖街道,小坝镇
    public final String townCode;//区县的下级行政区划代码:街道,镇 510726108
    public final String street;//街道:美专校街
    public final String streetNumber;//街道号码:9号
    public final String address;//地址:中国重庆市渝中区美专校街9号
    public final String adcode;//500103


    private ZAddress(Builder builder) {
        this.country = builder.mCountry;
        this.countryCode = builder.mCountryCode;
        this.province = builder.mProvince;
        this.provinceCode = builder.mProvinceCode;
        this.city = builder.mCity;
        this.cityCode = builder.mCityCode;
        this.district = builder.mDistrict;
        this.districtCode = builder.mDistrictCode;
        this.town = builder.mTown;
        this.townCode = builder.mTownCode;
        this.street = builder.mStreet;
        this.streetNumber = builder.mStreetNumber;
        this.address = builder.mAddress;
        this.adcode = builder.mAdcode;
        this.latitude = builder.mLatitude;
        this.longitude = builder.mLongitude;
    }

    @Keep
    public static class Builder {
        private double mLatitude;//纬度
        private double mLongitude;//经度
        private String mCountry = null;//国家:中国
        private String mCountryCode = null;//国家代码:GCJ02
        private String mProvince = null;//省份:重庆市
        private String mProvinceCode=null;//省份:重庆市
        private String mCity = null;//城市:重庆市
        private String mCityCode = null;//城市代码:023
        private String mDistrict = null;//区县:渝中区,北川羌族自治县
        private String mDistrictCode=null;//区:500103
        private String mTown = null;//区县的下级:街道,镇:宝圣湖街道,小坝镇
        private String mTownCode=null;//区县的下级行政区划代码:街道,镇
        private String mStreet = null;//街道:美专校街
        private String mStreetNumber = null;//街道号码:9号
        private String mAddress = null;//地址:中国重庆市渝中区美专校街9号
        private String mAdcode = null;//500103

        public Builder() {

        }

        public Builder latitude(double latitude) {
            this.mLatitude = latitude;
            return this;
        }

        public Builder longitude(double longitude) {
            this.mLongitude = longitude;
            return this;
        }

        public Builder country(String country) {
            this.mCountry = country;
            return this;
        }

        public Builder adcode(String adcode) {
            this.mAdcode = adcode;
            return this;
        }

        public Builder countryCode(String countryCode) {
            this.mCountryCode = countryCode;
            return this;
        }

        public Builder province(String province) {
            this.mProvince = province;
            return this;
        }

        public Builder provinceCode(String provinceCode) {
            this.mProvinceCode = provinceCode;
            return this;
        }

        public Builder city(String city) {
            this.mCity = city;
            return this;
        }

        public Builder cityCode(String cityCode) {
            this.mCityCode = cityCode;
            return this;
        }

        public Builder district(String district) {
            this.mDistrict = district;
            return this;
        }

        public Builder districtCode(String districtCode) {
            this.mDistrictCode = districtCode;
            return this;
        }

        public Builder town(String town) {
            this.mTown = town;
            return this;
        }

        public Builder townCode(String townCode) {
            this.mTownCode = townCode;
            return this;
        }

        public Builder street(String street) {
            this.mStreet = street;
            return this;
        }

        public Builder streetNumber(String streetNumber) {
            this.mStreetNumber = streetNumber;
            return this;
        }

        public Builder address(String address) {
            this.mAddress = address;
            return this;
        }

        public ZAddress build() {
            if (TextUtils.isEmpty(mAddress)) {
                StringBuffer var1 = new StringBuffer();
                if (this.mCountry != null) {
                    var1.append(this.mCountry);
                }
                if (this.mProvince != null) {
                    var1.append(this.mProvince);
                }

                if (this.mProvince != null && this.mCity != null && !this.mProvince.equals(this.mCity)) {
                    var1.append(this.mCity);
                }

                if (this.mDistrict != null) {
                    if (this.mCity != null) {
                        if (!this.mCity.equals(this.mDistrict)) {
                            var1.append(this.mDistrict);
                        }
                    } else {
                        var1.append(this.mDistrict);
                    }
                }

                if (this.mStreet != null) {
                    var1.append(this.mStreet);
                }

                if (this.mStreetNumber != null) {
                    var1.append(this.mStreetNumber);
                }

                if (var1.length() > 0) {
                    this.mAddress = var1.toString();
                }
            }


            return new ZAddress(this);
        }
    }

}
